package com.example.smartall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smartall.R;
import com.example.smartall.api.ApiConfig;
import com.example.smartall.entity.CarParkingListBean;

import java.util.List;

/**
 * @author abbas
 * @brief description
 * @date 2022-01-30
 */
public class CarParkingListAdapter extends BaseAdapter {

    private Context context;
    private List<CarParkingListBean.RowsBean> beans;

    public CarParkingListAdapter(Context context, List<CarParkingListBean.RowsBean> beans) {
        this.context = context;
        this.beans = beans;
    }

    @Override
    public int getCount() {
        return beans.size();
    }

    @Override
    public Object getItem(int i) {
        return beans.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.common_list_item,null,false);
            viewHolder.img = (ImageView) convertView.findViewById(R.id.img);
            viewHolder.title = (TextView) convertView.findViewById(R.id.title);
            viewHolder.subtitle = (TextView) convertView.findViewById(R.id.subtitle);
            viewHolder.content = convertView.findViewById(R.id.content);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        Glide.with(context).load(ApiConfig.BASE_URL + beans.get(i).getImgUrl()).into(viewHolder.img);
        viewHolder.title.setText(beans.get(i).getParkName());
        viewHolder.subtitle.setText("收费费率："+beans.get(i).getRates()+"元");
        viewHolder.content.setText("地址："+beans.get(i).getAddress()+"\n"
        +"空位数量："+beans.get(i).getVacancy()+"\n"
        +"距离我："+beans.get(i).getDistance());
        return convertView;
    }

    class ViewHolder {
        private ImageView img;
        private TextView title;
        private TextView subtitle;
        private TextView content;
    }
}

